import { RouteRecordRaw } from 'vue-router';

import { handleModuleRoutes } from '../../utils';

/** 读取当前相对目录下的 *.ts 文件 */
const modules = import.meta.glob('./**/*.ts', { eager: true }) as AuthRoute.RouteModule;

/** 加载 modlues 的路由 */
export const routes = handleModuleRoutes(modules);

/** 将 authRoute 转 vue-router */
export const convertToRouteRecordRaw = (authRoute: AuthRoute.Route) => {
    const router: RouteRecordRaw = {
        name: authRoute.name,
        path: authRoute.path,
        component: authRoute.component,
        meta: {
            title: authRoute.meta.title,
            requiresAuth: authRoute.meta.requiresAuth
        }
    };
    return router;
};
